package com.jd.webapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jd.common.convention.TTResult;
import com.jd.goods.pojo.GoodsCategorySpecification;
import com.jd.goods.service.GoodsCategorySpecificationService;



@Controller
public class GoodsCatSpecController {
	@Autowired
	private GoodsCategorySpecificationService goodsSpec;
	
	@RequestMapping("/item/param/query/itemcatid/{cid}")
	public @ResponseBody TTResult getItemParamByCid(@PathVariable Long cid){
		try {
			GoodsCategorySpecification itemParam = goodsSpec.getGoodsCategorySpecification(cid);
			if(itemParam==null || StringUtils.isEmpty(itemParam.getSpecifications())){
				return TTResult.ok();
			}else{
				return TTResult.ok(itemParam);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return TTResult.fail();
		}
	}
	
	@RequestMapping("/item/param/save/{cid}")
	public @ResponseBody TTResult addItemParam(@PathVariable Long cid,String paramData){
		try {
			GoodsCategorySpecification record = new GoodsCategorySpecification();
			record.setGoodsCatId(cid);
			record.setSpecifications(paramData);
			goodsSpec.add(record);
			return TTResult.ok();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return TTResult.fail();
	}
}
